<template>
	<div class="order-detail-page" v-if="order">
		<DetailAction :order="order"></DetailAction>
		<DetailSteps :order="order"></DetailSteps>

		<Suspense v-if="[3,4,5].includes(order.orderState)">
			<template #default>
				<DetailLogistics :order="order"></DetailLogistics>
			</template>
			<!-- 组件加载中显示 -->
			<template #fallback>
				<div class="loading">loading...</div>
			</template>
		</Suspense>
		
		<DetailInfo :order="order"></DetailInfo>
	</div>
</template>

<script>
	import {
		ref
	} from 'vue'
	import {
		findOrder
	} from '@/api/order'
	import {
		useRoute
	} from 'vue-router'
	import DetailAction from './components/detail-action'
	import DetailSteps from './components/detail-steps'
	import DetailLogistics from './components/detail-logistics'
	import DetailInfo from './components/detail-info'

	export default {
		components: {
			DetailAction,
			DetailSteps,
			DetailLogistics,
			DetailInfo
		},

		setup() {
			const order = ref(null)
			const route = useRoute()
			findOrder(route.params.id).then(data => {
				order.value = data.result
			})

			return {
				order
			}
		}
	}
</script>

<style lang="less" scoped>
	.order-detail-page {
		background: #fff;
		height: 100%;
	}

	.loading {
		height: 50px;
		display: flex;
		align-items: center;
		padding: 0 30px;
		background-color: #f5f5f5;
		margin: 30px 50px 0;
	}
</style>
